import { defineStore } from "pinia";
import { ref } from "vue";
import { reqCategoryList, reqHomeData } from "../api/home/home";
import help from "../utils/help";

export const useHomeStore = defineStore("home", () => {
  //首页推荐数据
  //icon数据
  const policyDescList = ref([]);
  //banner轮播数据
  const focusList = ref([]);
  //icon分类数据
  const kingKongList = ref([]);
  //navbar数据
  const categoryList = ref([]);
  //热销榜单总数据
  const categoryHotSellModule = ref({});
  //新人福利数据
  const indexActivityModule = ref([]);
  //拆解底部动态数据
  const styleBanner = ref({});
  const styleItem = ref({});
  //分类界面banner图
  const bannerLIst = ref([]);
  //下拉刷新数据
  const oneCategoryList:any = ref([]);
  //下拉刷新控制push的index
  const index: any = ref(0);
  //获取首页推荐数据
  const getHomeData = async () => {
    let res = await reqHomeData();
    policyDescList.value = res.data.policyDescList;
    focusList.value = res.data.focusList;
    kingKongList.value = res.data.kingKongModule.kingKongList;
    categoryList.value = res.data.categoryHotSellModule.categoryList;
    indexActivityModule.value = res.data.indexActivityModule;
    categoryHotSellModule.value = res.data.categoryHotSellModule;
    styleBanner.value = res.data.sceneLightShoppingGuideModule[0].styleBanner;
    styleItem.value = res.data.sceneLightShoppingGuideModule[1].styleItem;
  };
  //获取首页分类数据
  const getCategoryList = async (categoryId: string) => {
    let res: any = await reqCategoryList(categoryId);
    bannerLIst.value = res.currentCategory.bannerList;
    oneCategoryList.value = res.categoryItemList;
  };
  return {
    policyDescList,
    focusList,
    kingKongList,
    categoryList,
    indexActivityModule,
    categoryHotSellModule,
    styleBanner,
    styleItem,
    bannerLIst,
    oneCategoryList,
    index,
    getHomeData,
    getCategoryList,
  };
});
